﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using mana.Web.UI.WebControls;

namespace TestWebSite.UI.WebControls
{
    public partial class ListControlExtensionsPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            var items = new List<Persona1>();
            for(int i = 1; i <= 20; i++)
            {
                items.Add(new Persona1 { Id = i, Apellido = "apellido " + i, Nombre = "nombre " + i, Fecha = DateTime.Now.AddDays(-i) });
            }

            combo.Load<Persona1>(items, "Apellido", "Id", true, "Seleccionar...");

            ActualizarSeleccionado();
        }

        protected void combo_SelectedIndexChanged(object sender, EventArgs e)
        {
            ActualizarSeleccionado();
        }

        private void ActualizarSeleccionado()
        {
            if (combo.SelectedItem == null)
                return;

            lblTexto.Text = combo.SelectedItem.Text;
            lblValor.Text = combo.SelectedValue;
        }
    }

    public class Persona1
    {
        public int Id { get; set; }
        public string Apellido { get; set; }
        public string Nombre { get; set; }
        public DateTime Fecha { get; set; }
    }
}